package com.tul.exercise.base.java8.stream.max;

import com.tul.exercise.base.java8.stream.base.Apple;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.util.Comparator;
import java.util.List;

/**
 * Stream的max()使用
 * @author tuliang
 */
public class MaxTest {
    @Test
    @DisplayName("Stream的max()方法")
    public void test01(){

        List<Apple> appleList = Apple.createApples(100);

        // 使用函数引用，找出重量最大的苹果
        Apple maxWeight = appleList.stream().max(Comparator.comparing(Apple::getWeight)).get();
        System.out.println(maxWeight);

        // 使用lambda表达式
        Apple maxWeight2 = appleList.stream().max(Comparator.comparing(apple -> apple.getWeight())).get();
        System.out.println(maxWeight2);

    }
}
